package com.hjlsoft.aftp.filter;

import java.io.IOException;
import java.util.Iterator;

import com.hjlsoft.aftp.ins.InsHandle;
import com.hjlsoft.aftp.network.Request;
import com.hjlsoft.aftp.network.Response;

public class DefaultInsFilterChain implements InsFilterChain {

	private Iterator<InsFilter> insFilterIterator;
	
	private InsHandle insHandle;
	
	public DefaultInsFilterChain(Iterator<InsFilter> insFilterIterator, InsHandle insHandle) {
		super();
		this.insFilterIterator = insFilterIterator;
		this.insHandle = insHandle;
	}

	public void doChain(Request request, Response response) throws IOException {
		if (insFilterIterator.hasNext()) {
			InsFilter insFilter = insFilterIterator.next();
			insFilter.onFilter(request, response, this);
		} else {
			insHandle.execute(request, response);
		}
	}

}
